Source Code Viewer - Example 9 - ViewManualParameterConversionsAction

package name.matthewgreet.example9.action;

import java.util.Date;
import org.apache.struts2.ActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import name.matthewgreet.example9.form.DateOfBirth2ManualParameterConversionForm;
import name.matthewgreet.example9.form.DateOfBirth2ManualParameterConversionForm.FormattedDateComponents;
import name.matthewgreet.example9.form.DateOfBirthManualParameterConversionForm;
import name.matthewgreet.example9.form.FlagManualParameterConversionForm;
import name.matthewgreet.example9.form.RatingManualParameterConversionForm;
import name.matthewgreet.example9.form.RequiredPriceManualParameterConversionForm;
import name.matthewgreet.example9.form.RequiredScoreManualParameterConversionForm;
import name.matthewgreet.example9.form.TechAttitudeManualParameterConversionForm;
import name.matthewgreet.example9.view.AttitudeSelectBoxDisplay;
import name.matthewgreet.example9.view.DayOfMonthSelectBoxDisplay;
import name.matthewgreet.example9.view.MonthSelectBoxDisplay;
import name.matthewgreet.example9.view.RatingSelectBoxDisplay;
import name.matthewgreet.example9.view.TechCompanySelectBoxDisplay;
import name.matthewgreet.example9.view.YearSelectBoxDisplay;
import name.matthewgreet.strutscommons.action.AbstractViewActionSupport;


/**
 * Displays tests of parameters manually converted to (usually non-string) unformatted fields.  
 */
@InterceptorRef("ViewStack")
@Results({
	@Result(name=ActionSupport.SUCCESS, location="/pages/ManualParameterConversions.jsp")
})
public class ViewManualParameterConversionsAction extends AbstractViewActionSupport {
	private static final long serialVersionUID = -7979376337555804889L;
	
	private RequiredScoreManualParameterConversionForm requiredScoreForm;
	private FlagManualParameterConversionForm flagForm;
	private DateOfBirthManualParameterConversionForm dateOfBirthForm;
	private RatingManualParameterConversionForm ratingForm;
	private TechAttitudeManualParameterConversionForm techAttitudeForm;
	private RequiredPriceManualParameterConversionForm requiredPriceForm;
	private DateOfBirth2ManualParameterConversionForm dateOfBirth2Form;

	private RatingSelectBoxDisplay ratingSelectBoxDisplay;
	private TechCompanySelectBoxDisplay techCompanySelectBoxDisplay;
	private AttitudeSelectBoxDisplay attitudeSelectBoxDisplay;
	private DayOfMonthSelectBoxDisplay dayOfMonthSelectBoxDisplay;
	private MonthSelectBoxDisplay monthSelectBoxDisplay;
	private YearSelectBoxDisplay yearSelectBoxDisplay;

	/*
	private FormattedDateComponents getFormattedDateComponents(Date value) {
		ActionContext actionContext;
		FormattedDateComponents result;
    	ConversionData dayConversionData, monthConversionData, yearConversionData;
    	Map<String, ConversionData> conversionErrors;
		
		result = DateOfBirth2ManualParameterConversionForm.formatDate(value);

		actionContext = ActionContext.getContext();
		conversionErrors = actionContext.getConversionErrors();
		dayConversionData = conversionErrors.get("dateOfBirth2Form.day");
		if (dayConversionData != null) {
			result.setDay((String)dayConversionData.getValue());
		}
		monthConversionData = conversionErrors.get("dateOfBirth2Form.month");
		if (monthConversionData != null) {
			result.setMonth((String)monthConversionData.getValue());
		}
		yearConversionData = conversionErrors.get("dateOfBirth2Form.year");
		if (yearConversionData != null) {
			result.setYear((String)yearConversionData.getValue());
		}
		
		return result;
	}
	*/
	
	private FormattedDateComponents getFormattedDateComponents(Date value) {
		FormattedDateComponents result;
		
		result = DateOfBirth2ManualParameterConversionForm.formatDate(value);
		return result;
	}
	
	
    @Action("/ViewManualParameterConversion")
    @Override
    public String execute() throws Exception {
    	FormattedDateComponents dateOfBirth2Components;
    	
    	if (requiredScoreForm == null) {
    		requiredScoreForm = new RequiredScoreManualParameterConversionForm();
    	}
    	if (flagForm == null) {
    		flagForm = new FlagManualParameterConversionForm();
    	}
    	if (dateOfBirthForm == null) {
    		dateOfBirthForm = new DateOfBirthManualParameterConversionForm();
    	}
    	if (ratingForm == null) {
    		ratingForm = new RatingManualParameterConversionForm();
    	}
    	if (techAttitudeForm == null) {
    		techAttitudeForm = new TechAttitudeManualParameterConversionForm();
    	}
    	if (requiredPriceForm == null) {
    		requiredPriceForm = new RequiredPriceManualParameterConversionForm();
    	}
    	if (dateOfBirth2Form == null) {
    		dateOfBirth2Form = new DateOfBirth2ManualParameterConversionForm();
    	}
	    
    	ratingSelectBoxDisplay = new RatingSelectBoxDisplay();
    	ratingSelectBoxDisplay.setSelectedValue(ratingForm.getRating());
    	techCompanySelectBoxDisplay = new TechCompanySelectBoxDisplay();
    	techCompanySelectBoxDisplay.setSelectedValue(techAttitudeForm.getTechCompany());
    	attitudeSelectBoxDisplay = new AttitudeSelectBoxDisplay();
    	attitudeSelectBoxDisplay.setSelectedValue(techAttitudeForm.getAttitude());
    	dateOfBirth2Components = getFormattedDateComponents(dateOfBirth2Form.getDateOfBirth());
    	dayOfMonthSelectBoxDisplay = new DayOfMonthSelectBoxDisplay();
    	dayOfMonthSelectBoxDisplay.setSelectedFormattedValueWithConversionError(dateOfBirth2Components.getDay(), "dateOfBirth2Form.day");
    	monthSelectBoxDisplay = new MonthSelectBoxDisplay();
    	monthSelectBoxDisplay.setSelectedFormattedValueWithConversionError(dateOfBirth2Components.getMonth(), "dateOfBirth2Form.month");
    	yearSelectBoxDisplay = new YearSelectBoxDisplay();
    	yearSelectBoxDisplay.setSelectedFormattedValueWithConversionError(dateOfBirth2Components.getYear(), "dateOfBirth2Form.year");
        
		return SUCCESS;
    }

	public RequiredScoreManualParameterConversionForm getRequiredScoreForm() {
		return requiredScoreForm;
	}
	public FlagManualParameterConversionForm getFlagForm() {
		return flagForm;
	}
	public DateOfBirthManualParameterConversionForm getDateOfBirthForm() {
		return dateOfBirthForm;
	}
	public RatingManualParameterConversionForm getRatingForm() {
		return ratingForm;
	}
	public TechAttitudeManualParameterConversionForm getTechAttitudeForm() {
		return techAttitudeForm;
	}
	public RequiredPriceManualParameterConversionForm getRequiredPriceForm() {
		return requiredPriceForm;
	}
	public DateOfBirth2ManualParameterConversionForm getDateOfBirth2Form() {
		return dateOfBirth2Form;
	}

	public RatingSelectBoxDisplay getRatingSelectBoxDisplay() {
		return ratingSelectBoxDisplay;
	}
	public TechCompanySelectBoxDisplay getTechCompanySelectBoxDisplay() {
		return techCompanySelectBoxDisplay;
	}
	public AttitudeSelectBoxDisplay getAttitudeSelectBoxDisplay() {
		return attitudeSelectBoxDisplay;
	}
	public DayOfMonthSelectBoxDisplay getDayOfMonthSelectBoxDisplay() {
		return dayOfMonthSelectBoxDisplay;
	}
	public MonthSelectBoxDisplay getMonthSelectBoxDisplay() {
		return monthSelectBoxDisplay;
	}
	public YearSelectBoxDisplay getYearSelectBoxDisplay() {
		return yearSelectBoxDisplay;
	}

}